package net.alche.fa.core.doing;

import net.alche.fa.core.model.Logic;
import net.alche.fa.core.model.FaValue;
import net.alche.fa.core.CodeLevel;
import net.alche.fa.core.SageStone;
import net.alche.fa.core.FaException;
import java.util.List;

//
// ( )
//
@FaAnnoDoing
public class BracketDo extends AbstractDoing {
  FaLogUtil faLogUtil = new FaLogUtil();

  @Override
  public boolean matched(String what, Logic g) {
    return "(".equals(what);
  }

  @Override
  public FaValue doing(Logic g, CodeLevel lvl, SageStone st) throws FaException {
    if (g.getObj() != null) {
      List<FaValue> params = getFaValueList(st, lvl, g);
      if (g.getObj().equals("fxLog")) {
        return this.faLogUtil.log(params, lvl);
      } else {
        FaValue fav = DotDo.callSageMethod(st, g.getObj(), params, lvl);
        return fav;
      }
    } else if (g.getParam() != null && !g.getParam().isEmpty()) {
      List<FaValue> params = getFaValueList(st, lvl, g);
      return params.get(0);
    } else {
      return super.getLogicDataVal(st, lvl, g);
    }
  }
}